/**
 * 流程执行记录公共类
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","msgServ"],
		function($,sysmanMain,msgServ) {
			
		'use strict';
		var _typeUrl = '/dictionary/getTree.action',_rootpath,
		flowHistoricUrl='/workFlow/query/flowHistoricsListDomain.action',
		externalUrl = '/flowItems/query/getListByIdentify.action'
		var public_method ={
			
			/**
			 * 外部流程执行信息方法
			 * @param _options.record 列表选中行
			 * @param _options.form 页面form对象
			 * @param _options.rootId	页面根节点id
			 * @param _options.flowStateSelector	流程状态字段选择器
			 */
			initExternalGrid:function(_options){
				private_method.initExternalGrid(_options)
					
			},
			
			/** 初始化自有流程执行信息方法
			 * @param _options.historicId	列表domid
			 * @param _options.record		流程主业务记录
			 * @param _options.field		流程id字段
			 * @param _options.fieldVal		流程字段值
			 * @param _options.editwindow   弹窗窗口
			 */
			initInternalGrid:function(_options){
				private_method.initInternalGrid(_options)
			}
			
		}
		
		var private_method = {
			/**
			 * 初始化自有流程执行信息方法
			 * @param _options.historicId
			 */
			initInternalGrid:function(_options){
				
				var _historicGrid,rootPath
				if(_options){
					if(_options.historicId){
						_historicGrid= $(_options.historicId)
					}else{
						if(options.editwindow){
							_historicGrid= $(options.editwindow).find('table.historics')
						}
					}
					
					
				}
				if(_options.historicId && _options.record && _options.record.flowInstId){
					
							
					if(_historicGrid && _historicGrid.length>0){
						
						rootPath = '/'+sysmanMain.getRootPath();
						//初始化节点信息查询配置						
						var _historicParam ={
							url : rootPath + flowHistoricUrl,
							queryParams:{flowInstId:_options.record.flowInstId}	
						}						
						
						
						var _datagridParam = {
							rownumbers:true,
							animate: true,
							collapsible: true,					
							striped:true,
							width : 'auto',
							border:true,
							//singleSelect:false,
							idField: 'id',								
							fitColumns: true,	
							columns:[
								[    {field:'name',title:'节点名称',width:60},    
									{field:'username',title:'处理人员',width:60},    
									  {field:'startTime',title:'到达时间',width:60,align:'center'},    
									{field:'endTime',title:'完成时间',width:60,align:'center'} ,
									{field:'description',title:'签收信息',width:60}
									
								]
							]		
						}	
							
						$.extend(_historicParam,_datagridParam)
						_historicGrid.datagrid(_historicParam);
						
					}
				}
			},
			initExternalGrid:function(_options){
				
				var _historicGrid,rootPath
				if(_options){
					if(_options.historicId){
						_historicGrid= $(_options.historicId)
					}else{
						if(options.editwindow){
							_historicGrid= $(options.editwindow).find('table.historics')
						}
					}			
				
					if( _options.historicField && _options.record){
						
						
						
						rootPath = '/'+sysmanMain.getRootPath();
						
						var _historicParam ={
							url :rootPath + externalUrl
						}
						//配置了url与流程字段，外部流程
						if(_options.historicUrl)
							_historicParam.url = rootPath + _options.historicUrl
						var _field = _options.historicField
						var _fieldValue = _options.record[_options.historicField]
						var _hisQryParam = {}
						_hisQryParam[_field]=_fieldValue
						_historicParam.queryParams = _hisQryParam
						if(window.console){
							console.info(' fieldName:' +  _field +',fieldValue:'+_fieldValue)
						}
						
						
						var _datagridParam = {
								rownumbers:true,
								animate: true,
								collapsible: true,					
								striped:true,
								width : 'auto',
								border:true,
								//singleSelect:false,
								idField: 'id',								
								fitColumns: true,	
								columns:[
									[    {field:'hjmc',title:'节点名称',width:60},    
										{field:'blrname',title:'处理人员',width:60},    
										  {field:'start_time',title:'到达时间',width:60,align:'center'},    
										{field:'end_time',title:'完成时间',width:60,align:'center'} ,
										{field:'over_days',title:'耗时（天）',width:60}
										
									]
								]		
							}	
									
							$.extend(_historicParam,_datagridParam)
							_historicGrid.datagrid(_historicParam);
					}
				}
			}
		}
		
		
		return public_method;
			
})